#pragma once

#include "LoggerGlobalDefine.h"
#include <string>
#include <iostream>
#include <memory>
#include <atomic>

FPLOGGER_BEGIN

class FPLOGGER_EXPORT GLoggerConfig {
public:
	~GLoggerConfig();
	static GLoggerConfig& GetInstance();
	void SetInitConfig(const std::string& topic,const std::string& logDir);

private:
	GLoggerConfig();
	GLoggerConfig(const GLoggerConfig&) = delete;
	GLoggerConfig& operator=(const GLoggerConfig&) = delete;
};

class FPLOGGER_EXPORT FpLogger
{
public:
	enum LogLevel {
		LogLevel_INFO = 0,
		LogLevel_WARNING,
		LogLevel_ERROR
	};

	FpLogger() = delete;
	FpLogger(const FpLogger&) = delete;
	FpLogger& operator = (const FpLogger&) = delete;
	FpLogger(const char* file, int line, const LogLevel& level);
	void SetInitConfig(const std::string& topic, const std::string& logDir);

	~FpLogger();

	std::ostream& Stream();

private:
	class Impl;
	std::unique_ptr<Impl> _impl;

	GLoggerConfig& _cfg;
	std::atomic<bool> _ifInit = false;
};

FPLOGGER_END

#define FP_LOG_INFO FpLog::FpLogger(__FILE__,__LINE__,FpLog::FpLogger::LogLevel_INFO).Stream()
#define FP_LOG_WARNING FpLog::FpLogger(__FILE__,__LINE__,FpLog::FpLogger::LogLevel_WARNING).Stream()
#define FP_LOG_ERROR FpLog::FpLogger(__FILE__,__LINE__,FpLog::FpLogger::LogLevel_ERROR).Stream()